<template>
	<view>
		<view class="list-item">
			<view class="left">
				<image :src="item.image" mode="widthFix"></image>
			</view>
			<view class="right">
				<view class="title">{{ item.title }}</view>
				<view class="title">{{ item.desc }}</view>
				<view class="title">{{ item.price }}</view>
			</view>
		</view>
		
		<button type="primary" @click="addCar">加入购物车</button>
	</view>
</template>

<script>
	import { mapMutations } from 'vuex'
	const db = uniCloud.database().collection('proGoods')
	
	export default {
		data() {
			return {
				item: {}
			};
		},
		onLoad({ _id }) {
			db.doc(_id).get({
				// 获取一个
				getOne: true
			}).then(resp => {
				console.log(resp)
				this.item = resp.result.data
				uni.setNavigationBarTitle({
					title: this.item.title
				})
			})
		},
		methods: {
			...mapMutations(['addToCarList']),
			addCar() {
				if(!this.item_id) return ;
				this.addToCarList({
					...this.item,
					count: 1,
					state: false
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
